package com.woniuxy.microsysserver.service.impl;

import com.woniuxy.microsysserver.bean.AdminInfo;
import com.woniuxy.microsysserver.bean.RoleInfo;
import com.woniuxy.microsysserver.mapper.RoleMapper;
import com.woniuxy.microsysserver.service.IRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(readOnly = true)
public class RoleServiceImpl implements IRoleService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public List<RoleInfo> findAll() {
        return roleMapper.findAll();
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void delete(Integer id) {
        roleMapper.delete(id);
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void update(RoleInfo roleInfo) {
        roleMapper.updateRole(roleInfo);
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void add(RoleInfo roleInfo) {
        roleMapper.add(roleInfo);
    }

    @Override
    public List<AdminInfo> findByRoleId(Integer id) {
        return roleMapper.findByRoleId(id);
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public void changePermit(Integer id, String permit) {
        roleMapper.changePermit(id,permit);
    }

    public RoleInfo findById(Integer id){
        return roleMapper.findById(id);
    }

}
